/********************************************************************
        created:        2010/02/22
        filename:       htl_io_multiplexing.hpp
        author:         HongLiang

        purpose:        io_multiplexing
*********************************************************************/
#ifndef __HTL_IO_MULTIPLEXING_HPP__
#define __HTL_IO_MULTIPLEXING_HPP_

#include "../container/htl_config.h"
#include "htl_io_event.h"
__HTL_BEGIN_NAMESPACE

template<typename IOMultiplexing>
class iomultiplexing {
public:
	HTL_RESULT event_init(int _maxfds = 1024);
	HTL_RESULT event_add(int fd, int events);
	HTL_RESULT event_mod(int fd, int events);
	HTL_RESULT event_del(int fd);
	HTL_RESULT event_register(int fd, ioevent::call_handler handler);
	HTL_RESULT event_unregister(int fd);
	HTL_RESULT event_poll(void* args, int timeout_ms);
	iomultiplexing() : event_ptr(new IOMultiplexing){ } 
	virtual ~iomultiplexing () { delete event_ptr; }
protected:
	ioevent* event_ptr;
};

template<typename IOMultiplexing>
HTL_RESULT iomultiplexing<IOMultiplexing>::event_init(int _maxfds) {
	return event_ptr->event_init(_maxfds);
}

template<typename IOMultiplexing>
HTL_RESULT iomultiplexing<IOMultiplexing>::event_add(int fd, int events) {
	return event_ptr->event_add(fd, events);
}

template<typename IOMultiplexing>
HTL_RESULT iomultiplexing<IOMultiplexing>::event_mod(int fd, int events) {
	return event_ptr->event_mod(fd, events);
}

template<typename IOMultiplexing>
HTL_RESULT iomultiplexing<IOMultiplexing>::event_del(int fd) {
	return event_ptr->event_del(fd);
}

template<typename IOMultiplexing>
HTL_RESULT iomultiplexing<IOMultiplexing>::event_register(int fd,ioevent::call_handler handler) {
	return event_ptr->event_register(fd, handler);
}

template<typename IOMultiplexing>
HTL_RESULT iomultiplexing<IOMultiplexing>::event_unregister(int fd) {
	return event_ptr->event_unregister(fd);
}

template<typename IOMultiplexing>
HTL_RESULT iomultiplexing<IOMultiplexing>::event_poll(void* args, int timeout_ms) {
	return event_ptr->event_poll(args, timeout_ms);
}
__HTL_END_NAMESPACE
#endif


